package lex.mtd.ui.details;

import javax.swing.border.EmptyBorder;

import org.lex.swing.graph.ProgressGraphPane;
import org.lex.swing.graph.ProgressModel;

import lex.mtd.core.FileBlock;
import lex.mtd.core.FileBlockSet;
import lex.mtd.utils.IReload;

public class ProgressPane extends ProgressGraphPane implements IReload
{
	private FileBlockSet fileSet = null;

	public ProgressPane()
	{
		super( null );
		this.setBorder( new EmptyBorder( 6, 6, 6, 6 ) );
	}

	public void setFileBlockSet( FileBlockSet fileSet )
	{
		this.fileSet = fileSet;
		ProgressModel model = this.getModel();
		model.removeAll();
		this.fillModel();
		// this.repaint();
	}

	private void fillModel()
	{
		if( null == fileSet )
			return;
		ProgressModel model = this.getModel();
		model.setMaximum( fileSet.getContentLength() );
		for( int i = 0; i < fileSet.getFileCount(); i++ )
		{
			FileBlock f = fileSet.getFileBlock( i );
			model.addRange( f.getStartPosition(), f.getStartPosition() + f.getOffset() );
		}
	}

	@Override
	public void reload()
	{
		this.fillModel();
		// this.repaint();
	}
}
